using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Acms.WebControls
{
    [DefaultProperty("Code")]
    [ToolboxData("<{0}:GoogleAnalytics runat=server></{0}:GoogleAnalytics>")]
    public class GoogleAnalytics : WebControl
    {
        private string code;

        public string Code
        {
            get { return code; }
            set { code = value; }
        }
	

        protected override void OnPreRender(EventArgs e)
        {
            string javascript = string.Format(@"
<script type=""text/javascript"">
        var gaJsHost = ((""https:"" == document.location.protocol) ? ""https://ssl."" : ""http://www."");
        document.write(unescape(""%3Cscript src='"" + gaJsHost + ""google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E""));
</script>
<script type=""text/javascript"">
var pageTracker = _gat._getTracker(""{0}"");
pageTracker._initData();
pageTracker._trackPageview();
</script>", code);
            Page.ClientScript.RegisterStartupScript(this.GetType(), this.Code, javascript, false);
            base.OnPreRender(e);
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
        }
    }
}
